﻿using Alos.Entity;
using Alos.IRepository;
using PetaPoco;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Alos.Repository
{
    public class ReComTestRepository : BaseRepository<ReComTestType>, IReComTestRepository
    {
        /// <summary>
        /// 根据用户编号获取教材
        /// </summary>
        /// <param name="id"></param>
        /// <param name="roleid"></param>
        /// <returns></returns>
        public dynamic GetReComTestByResouceId(int id)
        {
            var sql = Sql.Builder.Append(@"select * from ReComTestType where ResourceID=@0
                                           select * from ReComDetail where ComID in (select ID from ReComTestType where ResourceID=@1)", id, id);

            var ComType = DBContext.SingleOrDefault<dynamic>("select * from ReComTestType where ResourceID=@0", id);
            var ComDetail = DBContext.Query<dynamic>("select * from ReComDetail where ComID in (select ID from ReComTestType where ResourceID=@0)", id);

            ComType.Detail = ComDetail;

            return ComType;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public IEnumerable<ReComDetail> GetReComTestById(int id)
        {

            var sql=Sql.Builder.Append("select * from ReComDetail where ComID in (select ID from ReComTestType where ResourceID=@0)", id);
            return DBContext.Query<ReComDetail>(sql);
        }
    }
}
